package com.kfm.jdbc.day03;

import com.kfm.jdbc.day02.DBHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo03 {

    public static void main(String[] args) {
        /**
         * 连续向数据库添加 100 条数据
         */
        String url = "jdbc:mysql://localhost:3306/company_info?useSSL=false&serverTimezone=UTC";

        DBHelper dbHelper = new DBHelper(url, "root", "root");

        try {
            Connection connection = dbHelper.getConnection();
            String sql = "insert into userinfo(username, userpass) values(?, ?)";
            long start = System.currentTimeMillis();
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            for (int i = 0; i < 100; i++) {
                preparedStatement.setObject(1, "张三");
                preparedStatement.setObject(2, "123456" + i);
                preparedStatement.executeUpdate();
            }

            System.out.println("耗时：" + (System.currentTimeMillis() - start) + "ms");

            preparedStatement.close();
            connection.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
